//
//  StatuesModel.m
//  SinaWeibo
//
//  Created by Apple on 16/8/14.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "StatuesModel.h"
#import "NSDate+NJ.h"

@implementation StatuesModel

+(NSDictionary *)objectClassInArray{
    
    return @{@"pic_urls":[pictureModel class]};
    
}


-(void)setSource:(NSString *)source{
    _source = source;
    
//    <a href="http://app.weibo.com/t/feed/3auC5p" rel="nofollow">皮皮时光机</a>
    
    NSRange startRange = [_source rangeOfString:@">"];
    
    NSRange endRange = [_source rangeOfString:@"</"];
    
    NSInteger starLoc = startRange.location + 1;
    
    NSInteger len = endRange.location - starLoc;
    
    NSRange subRange = NSMakeRange(starLoc, len);
    
    if (startRange.location != NSNotFound ) {
        NSString *sourceString = [_source substringWithRange:subRange];
        
        _source = sourceString;
    }
}


-(NSString *)created_at{
    
    //
    //    1.今年发布
    //    1.1今天
    //    1分钟以内：刚刚     1小时以内:多少分钟前     大于1小时 : 多少小时前
    //    1.2昨天 ：昨天 xx时：xx分
    //
    //    1.3其它天：xx月xx日  xx时xx分
    //    2.非今年：xx年xx月xx日 xx时:xx分
    
    //将服务器返回的时间可视化
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    
    //真机要设置地区
    formatter.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"en_US"];
    
    //设置格式
    formatter.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy";
    
    NSDate *creatDate = [formatter dateFromString:_created_at];
    
    NSDateComponents *delta = [creatDate deltaWithNow];
    if ([creatDate isThisYear]) {
        
        if ([creatDate isToday]) {
            
            if (delta.hour >= 1) {
                
                return [NSString stringWithFormat:@"%tu小时前",delta.hour];
                
            }else if(delta.minute >= 1){
                
                return [NSString stringWithFormat:@"%tu分钟前",delta.minute];
                
            }else{
                
                return @"刚刚";
            }
        }else{
            
            return [NSString stringWithFormat:@"%tu月%tu日 %tu分%tu秒",delta.month,delta.day,delta.hour,delta.minute];
        }
        
    }else{
        return [NSString stringWithFormat:@"%tu年%tu月%tu日 %tu时:%tu分",delta.year,delta.month,delta.day,delta.hour,delta.minute];
    }
    
}


@end
